package org.deltaset.meta.faces;

import org.deltaset.meta.EntityResolver;
import org.deltaset.meta.OptionBuilder;
import org.deltaset.meta.TitleResolver;
import org.deltaset.meta.aware.MetaHandlerProviderAware;
import org.deltaset.meta.aware.RepositoryProviderAware;
import org.deltaset.meta.aware.TitleResolverProviderAware;
import org.deltaset.meta.extension.MetaHandlerProvider;
import org.deltaset.meta.extension.OptionBuilderProvider;
import org.deltaset.meta.extension.RepositoryProvider;
import org.deltaset.meta.extension.TitleResolverProvider;

/**
 *
 * @author Dimitar Makariev
 */
public class OptionBuilderProviderImpl implements OptionBuilderProvider, MetaHandlerProviderAware, RepositoryProviderAware, TitleResolverProviderAware {

    private MetaHandlerProvider metaHandlerProvider;
    private RepositoryProvider repositoryProvider;
    private TitleResolverProvider titleResolverProvider;

    @Override
    public <T> OptionBuilder<T> createOptionBuilder() {
        final EntityResolver entityResolver = repositoryProvider.createEntityResolver();
        final TitleResolver titleResolver = titleResolverProvider.createTitleResolver();
        return (OptionBuilder<T>) new SelectOptionBuilderImpl(metaHandlerProvider, entityResolver, titleResolver);
    }

    @Override
    public void setMetaHandlerProvider(final MetaHandlerProvider metaHandlerProvider) {
        this.metaHandlerProvider = metaHandlerProvider;
    }

    @Override
    public void setRepositoryProvider(RepositoryProvider repositoryProvider) {
        this.repositoryProvider = repositoryProvider;
    }

    @Override
    public void setTitleResolverProvider(TitleResolverProvider titleResolverProvider) {
        this.titleResolverProvider = titleResolverProvider;
    }
}
